package com.example.demo.controller;


import com.example.demo.domain.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;

@Controller
public class StudentController {
    /*    表现层*/
    @Autowired
    StudentService studentService;


    @RequestMapping("/list")
    public String list(Model model){
        List<Student> student= studentService.findAll();
        System.out.println(student);
        model.addAttribute("data",student);
        return "list";
    }

    @RequestMapping("/insert")
    public String insert(Student student){
        System.out.println(student);
        Student insert = studentService.insert(student);
        return "forward:/list";
    }
}
